package com.yxy.controller.admin;

import com.yxy.common.PageResult;
import com.yxy.common.Result;
import com.yxy.constant.RequestMapperConstant;
import com.yxy.pojo.dto.BannerDTO;
import com.yxy.pojo.dto.BannerPageQueryDTO;
import com.yxy.service.BannerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(RequestMapperConstant.ADMIN_REQUEST_MAPPER + "banner")
@Slf4j
public class BannerController {

    @Autowired
    private BannerService bannerService;

    /**
     * 分页查询轮播图列表
     * @return
     */
    @GetMapping("/pageQuery")
    public Result<PageResult> pageQuery(BannerPageQueryDTO bannerPageQueryDTO){
        log.info("分页查询轮播图列表：{}", bannerPageQueryDTO);
        PageResult pageResult = bannerService.pageQuery(bannerPageQueryDTO);
        return Result.success("", pageResult);
    }

    /**
     * 添加轮播图
     * @param bannerDTO
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody BannerDTO bannerDTO){
        log.info("添加轮播图：{}", bannerDTO);
        bannerService.add(bannerDTO);
        return Result.success("新增成功");
    }

    /**
     * 修改轮播图状态
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/update/{id}/{status}")
    public Result updateStatus(@PathVariable int id, @PathVariable int status){
        log.info("修改轮播图状态：{}, {}", id, status);
        bannerService.updateStatus(id, status);
        return Result.success("", null);
    }

    /**
     * 批量删除轮播图
     * @param ids
     * @return
     */
    @DeleteMapping("/deleteByIds")
    public Result batchDelete(@RequestParam int[] ids){
        log.info("批量删除轮播图：{}", ids);
        bannerService.batchDelete(ids);
        return Result.success("删除成功");
    }
}
